package com.weetop.akly.activity.mine;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.classic.adapter.BaseAdapterHelper;
import com.classic.adapter.CommonRecyclerAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import com.weetop.akly.R;
import com.weetop.akly.activity.communicationIndex.DepartmentActivity;
import com.weetop.akly.activity.meessage.ShenpiDetailActivity;
import com.weetop.akly.adapter.ViewPagerAdapter;
import com.weetop.akly.base.BaseActivity;
import com.weetop.akly.base.mvp.BasePresenter;
import com.weetop.akly.bean.ApproveItem;
import com.weetop.akly.bean.PostMessage;
import com.weetop.akly.utils.BaseUtils;
import com.weetop.akly.utils.EventBusUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AlpplyListActivity extends BaseActivity {

    @BindView(R.id.tablayout)
    TabLayout tablayout;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    private String[] titles;

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    private CommonRecyclerAdapter<String> adapter;
    String id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alpply_list);
        ButterKnife.bind(this);
        id = getIntent().getStringExtra("id");
        if (id.equals("1")) {
            setTitleInfo("申请记录");
            titles = new String[]{"请假申请", "外出申请", "外勤申请", "加班申请"};
        } else {
            setTitleInfo("审批记录");
            titles = new String[]{"请假审批", "外出审批", "外勤审批", "加班审批"};
        }
        initView();
    }

    private List<Fragment> fragments = new ArrayList<>();

    private void initView() {
        fragments.add(ApplyListFragment.instance("2", id));
        fragments.add(ApplyListFragment.instance("3", id));
        fragments.add(ApplyListFragment.instance("4", id));
        fragments.add(ApplyListFragment.instance("5", id));

        viewpager.setOffscreenPageLimit(4);
        viewpager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return titles[position];
            }

            @Override
            public int getCount() {
                return 4;
            }
        });
        viewpager.setOffscreenPageLimit(2);
        tablayout.setupWithViewPager(viewpager);
        viewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                PostMessage postMessage = new PostMessage();
                postMessage.setKey(i + 2 + "");
                EventBusUtil.sendEvent(postMessage);
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
    }
}
